home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / AppInstall / Util.py < prev    next >
Encoding:
Python Source  |  2009-03-31  |  3.4 KB  |  122 lines

  1. # misc utils
  2. # (c) 2005-2007 Canonical, GPL
  3. # Authors:
  4. #  Michael Vogt
  5.  
  6. import os
  7. import os.path
  8. import apt_pkg
  9.  
  10. # Column enumeration
  11.  
  12. # Columns of the categories store
  13. (COL_CAT_NAME,
  14.  COL_CAT_ITEM) = range(0,2)
  15.  
  16. # Columns of the packages store
  17. (COL_NAME,
  18.  COL_ITEM,
  19.  COL_POPCON) = range(3)
  20.  
  21. def get_maintenance_end_date(release_date, m_months):
  22.     """
  23.     get the (year, month) tuple when the maintenance for the distribution
  24.     ends
  25.     """
  26.     years = m_months / 12
  27.     months = m_months % 12
  28.     support_end_year = release_date.year + years + (release_date.month + months)/12
  29.     support_end_month = (release_date.month + months) % 12
  30.     return (support_end_year, support_end_month)
  31.  
  32. def get_release_date_from_release_file(path):
  33.     """
  34.     return the release date as time_t for the given release file
  35.     """
  36.     if not path or not os.path.exists(path): 
  37.         return None
  38.     tag = apt_pkg.ParseTagFile(open(path))
  39.     tag.Step()
  40.     if not tag.Section.has_key("Date"):
  41.         return None
  42.     date = tag.Section["Date"]
  43.     return apt_pkg.StrToTime(date)
  44.  
  45. def get_release_filename_for_pkg(cache, pkgname, label, release):
  46.     " get the release file that provides this pkg "
  47.     if not cache.has_key(pkgname):
  48.         return None
  49.     pkg = cache[pkgname]
  50.     ver = None
  51.     # look for the version that comes from the repos with
  52.     # the given label and origin
  53.     for aver in pkg._pkg.VersionList:
  54.         if aver == None or aver.FileList == None:
  55.             continue
  56.         for verFile, index in aver.FileList:
  57.             #print verFile
  58.             if (verFile.Origin == label and 
  59.                 verFile.Label == label and
  60.                 verFile.Archive == release):
  61.                 ver = aver
  62.     if not ver:
  63.         return None
  64.     indexfile = cache._list.FindIndex(ver.FileList[0][0])
  65.     for metaindex in cache._list.List:
  66.         for m in metaindex.IndexFiles:
  67.             if (indexfile and 
  68.                 indexfile.Describe == m.Describe and
  69.                 indexfile.IsTrusted):
  70.                 dir = apt_pkg.Config.FindDir("Dir::State::lists")
  71.                 name = apt_pkg.URItoFileName(metaindex.URI)+"dists_%s_Release" % metaindex.Dist
  72.                 return dir+name
  73.     return None
  74.  
  75. def xmlescape(s):
  76.     from xml.sax.saxutils import escape
  77.     if s==None:
  78.         return ""
  79.     else:
  80.         return escape(s)
  81.  
  82.  
  83. def iterate_list_store(store, it):
  84.     """ iterate over a gtk tree-model, returns a gtk.TreeIter for each element
  85.     """
  86.     if not it:
  87.         raise StopIteration
  88.     yield it
  89.     while True:
  90.         it = store.iter_next(it)
  91.         if it == None:
  92.             raise StopIteration
  93.         yield it
  94.     
  95.  
  96.  
  97. # class SimpleFilteredCache(apt.cache.FilteredCache):
  98. #     """ a simpler version of the filtered cache that will not react to
  99. #         cache changed (no need, we are only interessted in text)
  100. #     """
  101. #     def filterCachePostChange(self):
  102. #         pass
  103. #     def runFilter(self):
  104. #         self._reapplyFilter()
  105.  
  106. # class SearchFilter(apt.cache.Filter):
  107. #     """ a filter class that just searchs insensitive in name/description """
  108. #     def SetSearchTerm(self, term):
  109. #         self._term = term.lower()
  110. #     def apply(self, pkg):
  111. #         if self._term in pkg.name.lower() or \
  112. #                self._term in pkg.description.lower():
  113. #             return True
  114. #         else:
  115. #             return False
  116. #     def __init__(self, query=None):
  117. #         if query != None:
  118. #             self.SetSearchTerm(query)
  119.  
  120.  
  121.  
  122.